//
//  HotListViewController.m
//  PlayerFix
//
//  Created by DAT on 15/11/5.
//  Copyright © 2015年 DAT. All rights reserved.
//

#import "HotListViewController.h"
#import "HotListModel.h"
#import "HotListCell.h"

#import "DATAsyncGetAFNBlock.h"

@interface HotListViewController ()<UITableViewDelegate, UITableViewDataSource>


@property (nonatomic, strong) UITableView *bgTableView;


@property (nonatomic, strong) NSMutableArray *listArray;


@end

@implementation HotListViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.bgTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 375, 667 - 64 - 30)];
    self.bgTableView.backgroundColor = [UIColor whiteColor];
    self.bgTableView.delegate = self;
    self.bgTableView.dataSource = self;
    [self.view addSubview:self.bgTableView];
    
    self.listArray = [NSMutableArray array];
    
    [self getAFNetworkingData];
    
    
    
}

- (void)getAFNetworkingData{
    
    //v=9&period=daily
    [DATAsyncGetAFNBlock GetAFNURLWithString:@"http://echosystem.kibey.com/hot/sounds" andBody:@{@"v":@"9", @"period":@"daily"} andCookie:@"PHPSESSID=q7o15e0lpjjkhd2ouv74h1b7l2" resultBlock:^(id result) {
        
//        NSLog(@"dailyResult **************************** %@",result);
        
        NSDictionary *resultDic = [result objectForKey:@"result"];
        NSArray *dataArray = [resultDic objectForKey:@"data"];
        for (NSDictionary *dic in dataArray) {
            
            HotListModel *hotListModel = [[HotListModel alloc] init];
            [hotListModel setValuesForKeysWithDictionary:dic];
            [self.listArray addObject:dic];
//            NSLog(@"hotlistmodel ------------- %@", hotListModel);
            
        }
        
        [self.bgTableView reloadData];
    } errorBlock:^(NSError *error) {
        
//        NSLog(@"dailyError ************************ %@", error);
    }];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
//    NSLog(@"listArray.count ================== %ld", self.listArray.count);
    return self.listArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
//    NSLog(@"tableview gogogogogogo");
    static NSString *cellIdentifier = @"cell";
    HotListModel *hotlist = [self.listArray objectAtIndex:indexPath.row];
    HotListCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        
        cell = [[HotListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.hotListModel = hotlist;
//    cell.nameLabel.text = hotlist.name;
//    cell.viewCountLabel.text = [NSString stringWithFormat:@"%@", hotlist.view_count];
//    NSLog(@"radiocell ============= %@", cell);
    return cell;
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 100;
}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
